package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.spider.process.LianJiaProcessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.SecondaryInfo;
import com.stylefeng.guns.modular.system.service.ISecondaryInfoService;

/**
 * 福州链家二手房成交数据控制器
 *
 * @author xxd
 * @Date 2020-05-08 16:54:13
 */
@Controller
@RequestMapping("/secondaryInfo")
public class SecondaryInfoController extends BaseController {

    private String PREFIX = "/system/secondaryInfo/";

    @Autowired
    private ISecondaryInfoService secondaryInfoService;

    @Autowired
    private LianJiaProcessor lianJiaProcessor;

    /**
     * 跳转到福州链家二手房成交数据首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "secondaryInfo.html";
    }

    /**
     * 跳转到添加福州链家二手房成交数据
     */
    @RequestMapping("/secondaryInfo_add")
    public String secondaryInfoAdd() {
        return PREFIX + "secondaryInfo_add.html";
    }

    /**
     * 跳转到修改福州链家二手房成交数据
     */
    @RequestMapping("/secondaryInfo_update/{secondaryInfoId}")
    public String secondaryInfoUpdate(@PathVariable Integer secondaryInfoId, Model model) {
        SecondaryInfo secondaryInfo = secondaryInfoService.selectById(secondaryInfoId);
        model.addAttribute("item",secondaryInfo);
        LogObjectHolder.me().set(secondaryInfo);
        return PREFIX + "secondaryInfo_edit.html";
    }

    /**
     * 获取福州链家二手房成交数据列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return secondaryInfoService.selectList(null);
    }

    /**
     * 新增福州链家二手房成交数据
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SecondaryInfo secondaryInfo) {
        secondaryInfoService.insert(secondaryInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除福州链家二手房成交数据
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer secondaryInfoId) {
        secondaryInfoService.deleteById(secondaryInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改福州链家二手房成交数据
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SecondaryInfo secondaryInfo) {
        secondaryInfoService.updateById(secondaryInfo);
        return SUCCESS_TIP;
    }

    /**
     * 福州链家二手房成交数据详情
     */
    @RequestMapping(value = "/detail/{secondaryInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("secondaryInfoId") Integer secondaryInfoId) {
        return secondaryInfoService.selectById(secondaryInfoId);
    }

    /**
     * 福州链家二手房成交数据详情爬虫
     */
    @RequestMapping(value = "/liajiaSpider")
    public void lianJiaSpider()
    {
        lianJiaProcessor.crawl();
    }
}
